﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using pcsse.App_Code.entity;

namespace pcsse.MasterPages
{
    public partial class common : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["ID"] != null)
            {
                Panel_logged.Visible = true;
                Panel_login.Visible = false;
                if (Convert.ToInt32(Session["Priority"]) >= 3) Panel_admin.Visible = true;
            }
            else
            {
                Panel_logged.Visible = false;
                Panel_login.Visible = true;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            login lg = new login();
            int loginresult = lg.LoginByNumber(tb_stuno.Text, tb_password.Text);
            if (loginresult <= 0)
            {
                lb_tip.Text = "验证失败";
            }else{
                Session["ID"] = loginresult.ToString();
                person_info pi = new person_info();
                int pid = pi.GetPriorityByID(loginresult);
                Session["Priority"] = pid;
                int bid = pi.GetBranchIDByID(loginresult);
                Session["Branch"] = bid;
                Panel_logged.Visible = true;
                Panel_login.Visible = false;
                if (pid >= 3) Panel_admin.Visible = true;
                Response.Redirect(Request.Url.ToString());
            }
        }

        protected void logoutLb_Click(object sender, EventArgs e)
        {
            Session.Clear();
            Response.Redirect("~/default.aspx");
        }
    }
}
